package org.vsg.security.model.service.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;

import org.vsg.common.biz.exception.ServiceException;
import org.vsg.common.pagination.Pagination;
import org.vsg.common.pagination.PaginationException;
import org.vsg.common.pagination.carrier.Carrier;
import org.vsg.common.pagination.carrier.RecordLimitCarrier;
import org.vsg.common.pagination.datatrans.PaginationProvider;
import org.vsg.common.pagination.datatrans.PaginationProviderFactory;
import org.vsg.security.model.domain.SysActor;
import org.vsg.security.model.persistence.SysActorDao;
import org.vsg.security.model.service.SysActorService;


public class SysActorServiceImpl implements SysActorService {
	/**
	 * set the pagination provider factory
	 * 
	 * 
	 */
	private PaginationProviderFactory factory = PaginationProviderFactory
			.getInstance();

	private SysActorDao sysActorDao;

	/**
	 * @param carrier
	 * @return
	 * @exception ServiceException
	 * @exception PaginationException
	 */
	public Pagination pageSysActor(Carrier carrier) throws ServiceException,
			PaginationException {
		// TODO: implement
		PaginationProvider provider = factory
				.generateProvider((RecordLimitCarrier) carrier);
		return sysActorDao.pageSysActor(provider);
	}

	/**
	 * @param carrier
	 * @return
	 * @throws ServiceException
	 * @exception PaginationException
	 */
	public Pagination pageSysActorByAll(Carrier carrier) throws ServiceException,
			PaginationException {
		// TODO: implement
		PaginationProvider provider = factory
				.generateProvider((RecordLimitCarrier) carrier);
		return sysActorDao.pageSysActorByAll(provider);
	}
	
	@Override
	public void saveAll(Collection<SysActor> all)
			throws ServiceException {
		// TODO Auto-generated method stub
		sysActorDao.saveAll(all);
		
	}  	

	/**
	 * @param sysActor
	 * @exception ServiceException
	 */
	public void addSysActor(SysActor sysActor) throws ServiceException {
		// TODO: implement
		sysActorDao.save(sysActor);
	}

	/**
	 * @param sysActor
	 * @exception ServiceException
	 */
	public void updateSysActor(SysActor sysActor) throws ServiceException {
		// TODO: implement
		sysActorDao.update(sysActor);
	}

	/**
	 * @param sysActor
	 * @exception ServiceException
	 */
	public void updateSimpleSysActor(SysActor newEntity) throws ServiceException {
		// TODO: implement
		SysActor original = sysActorDao.load( newEntity.getId() );
		
		original.setId( newEntity.getId()  );
		original.setFlagDisable( newEntity.getFlagDisable()  );
		
		// --- update the method ---
		sysActorDao.update( original );		
		
	}

	/**
	 * @param sysActor
	 * @exception ServiceException
	 */
	public void deleteSysActor(SysActor sysActor) throws ServiceException {
		// TODO: implement
		sysActorDao.delete(sysActor);
	}

	@Override
	public void deleteAll(Collection<SysActor> all)
			throws ServiceException {
		// TODO Auto-generated method stub
		sysActorDao.deleteAll(all);
	}
	
	@Override
	public void markDeleteSysActor(SysActor sysActor) throws ServiceException {
		// TODO Auto-generated method stub
		SysActor loadSysActor = sysActorDao.load( sysActor.getId() );
		loadSysActor.setFlagDeleted( (short)1 );
		sysActorDao.update( loadSysActor );
	}	

	/**
	 * @param pk
	 * @exception ServiceException
	 */
	public SysActor loadSysActor(Serializable pk) throws ServiceException {
		// TODO: implement
		return sysActorDao.load(pk);
	}

	@Override
	public SysActor getByCode(String code) throws ServiceException {
		// TODO Auto-generated method stub
		Collection<SysActor> some = sysActorDao.findByCode(code);
		SysActor sysActor = null;
		Iterator<SysActor> itera = some.iterator();
		if ( itera.hasNext() ) {
			sysActor = itera.next();
		}
		return sysActor;
	}

	@Override
	public Collection<SysActor> findByAll() throws ServiceException {
		// TODO Auto-generated method stub
		return sysActorDao.findByAll();
	}


	public SysActorDao getSysActorDao() {
		return sysActorDao;
	}

	/**
	 * @param newSysActorDao
	 */
	public void setSysActorDao(SysActorDao newSysActorDao) {
		sysActorDao = newSysActorDao;
	}




}